package com.lanou.service.impl;

import com.lanou.bean.User;
import com.lanou.bean.UserComments;
import com.lanou.mapper.UserCommentMapper;
import com.lanou.service.UserCommentService;
import com.lanou.utils.AjaxResult;
import com.lanou.utils.StrUtils;
import com.lanou.utils.TimeUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dllo on 18/3/15.
 */
@Service
public class UserCommentServiceImpl implements UserCommentService {
    @Resource
    private UserCommentMapper userCommentMapper;

    /**
     * 用户添加评论
     *
     * @param state        施工状态
     * @param designNum    设计分数
     * @param serviceNum   服务分数
     * @param constructNum 施工分数
     * @param userContent  用户评论内容
     * @param productId    产品id
     *                     开发人:赵帅
     */
    @Override
    public void userComment(String state, Integer designNum, Integer serviceNum, Integer constructNum, String userContent, Integer productId,Integer company_id) {
        long time = System.currentTimeMillis();
        String commentTime = TimeUtils.timeTool(time);
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String nickname = StrUtils.charSetStr(user.getU_nickname());
        Integer user_id = user.getU_id();
        state = StrUtils.charSetStr(state);
        userContent = StrUtils.charSetStr(userContent);
        String commentLevel = null;
        if ((designNum + serviceNum + constructNum) >= 12) {
             commentLevel = "好评";
        } else if ((designNum + serviceNum + constructNum) >= 6) {
            commentLevel = "中评";
        }else {
            commentLevel = "差评";
        }
        userCommentMapper.insertUserComment(state, designNum, serviceNum, constructNum, userContent, commentTime, nickname,commentLevel, productId, user_id,company_id);

    }

    /**
     * 回复评论人的信息
     *
     * @param repeatContent 回复内容
     * @param id            回复哪条评论的id号
     *                      开发人:赵帅
     */
    @Override
    public void repeatComment(String repeatContent, Integer id) {
        long time = System.currentTimeMillis();
        String repeatTime = TimeUtils.timeTool(time);
        repeatContent = StrUtils.charSetStr(repeatContent);
        userCommentMapper.insertRepeatComment(id, repeatTime, repeatContent);
    }


}
